package com.trkj.controllers;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.trkj.vo.Info;
import com.trkj.pojos.EquipOrder;
import com.trkj.pojos.EquipRepair;
import com.trkj.service.BusinessService;
import com.trkj.service.EplanOrderService;
import com.trkj.service.EquipDeliveryService;
import com.trkj.service.EquipPlanService;
import com.trkj.service.EquipRepairService;
import com.trkj.service.EquipSoService;
import com.trkj.service.EquipStorageService;
import com.trkj.service.OrderPlanService;
import com.trkj.service.PatientRegistrationService;
import com.trkj.service.StorageReturnService;
import com.trkj.vo.BusinessVo;
import com.trkj.vo.EosDeliveryVo;
import com.trkj.vo.EosReturnVo;
import com.trkj.vo.EquipPlanVo;
import com.trkj.vo.EquipStorageVo;

@Controller
public class HospEquipController {
	
	@GetMapping("/to_plan_add")
	public String toEquipPlanAdd(){
		return "equip_plan_add";
	}
	@RequestMapping("/to_EquipPlanLook")
	public String toEquipPlanLook(){
		return "equip_plan_look";
	}
	@RequestMapping("/to_EditeBusiness")
	public String toEditeBusiness(){
		return "equip_business_edite";
	}
	@RequestMapping("/to_EquipPlanEdite")
	public String toEquipPlanEdite(){
		return "equip_plan_edite";
	}
	@GetMapping("/to_plan_list")
	public String toEquipPlanList(){
		return "equip_plan_list";
	}
	@GetMapping("/to_supplier_add")
	public String to_supplier_add(){
		return "equip_supplier_add";
	}
	@GetMapping("/to_supplier_list")
	public String toSupplierList(){
		return "equip_supplier_list";
	}
	@GetMapping("/to_order_add")
	public String toOrderAdd(){
		return "equip_order_add";
	}
	@GetMapping("/to_order_list")
	public String toOrderList(){
		return "equip_order_list";
	}
	@GetMapping("/to_order_save")
	public String toOrderSave(){
		return "equip_order_save";
	}
	@GetMapping("/to_return_list")
	public String toOrderReturn(){
		return "equip_order_return";
	}
	@GetMapping("/to_equip_list")
	public String toEquipList(){
		return "equip_list";
	}
	@GetMapping("/to_repair_add")
	public String toRepairAdd(){
		return "equip_repair_add";
	}
	@GetMapping("/to_repair_list")
	public String toRepairList(){
		return "equip_repair_list";
	}
	@GetMapping("/to_depreciation_add")
	public String toDepreciationAdd(){
		return "equip_depreciation_add";
	}
	@GetMapping("/to_depreciation_order")
	public String toDepreciationOrder(){
		return "equip_depreciation_order";
	}
	@GetMapping("/to_depreciation_list")
	public String toDepreciationList(){
		return "equip_depreciation_list";
	}
	
	@GetMapping("/equip_supply_office")
	public String toEquipSupplyOffice(){
		return "equip_supply_office";
	}
	
	
	
	@Autowired
	private EquipSoService equipSoService;
	/**
	 * 查询基础数据
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/getEquip_list")
	@ResponseBody
	public Map<String,Object> getEquip(int page, int rows,String where){
		return equipSoService.getEquip(page, rows,where);
	}
	@RequestMapping("/getSupply_list")
	@ResponseBody
	public Map<String,Object> getSupply(int page, int rows,String where){	
		return equipSoService.getSupply(page, rows,where);
	}
	@RequestMapping("/getOffice_list")
	@ResponseBody
	public Map<String,Object> getOffice(int page, int rows,String where){
		return equipSoService.getOffice(page, rows,where);
	}
	
	/**
	 * 添加计划
	 */
	@Autowired
	private EquipPlanService equipPlanService;
	
	@PostMapping("/add_equiplan")
	@ResponseBody
	public Info addPlan(EquipPlanVo planVo){
		boolean flag = equipPlanService.addPlan(planVo.getEplan(), 
				Arrays.asList(planVo.getPlanDetails()));
		return flag ? new Info() : new Info("采购计划增加失败！");
	}
	/**
	 * 编辑计划
	 */
	@PostMapping("/edite_equiplan")
	@ResponseBody
	public Info editePlan(long eplanId,EquipPlanVo planVo){
		boolean flag = equipPlanService.editePlan(eplanId, planVo.getEplan(), 
				Arrays.asList(planVo.getPlanDetails()));
		return flag ? new Info() : new Info("采购计划编辑失败！");
	}
	/**
	 * 刪除计划
	 * @param eplanId
	 */
	
	@PostMapping("/delete_eplan")
	@ResponseBody
	public boolean deletePlan(long eplanId){
		return equipPlanService.deletePlan(eplanId);	
	}
	/**
	 * 审核计划
	 * @param eplanId
	 */
	@PostMapping("/checked_Eplan")
	@ResponseBody
	public boolean CheckedEplan(long eplanId){
		return equipPlanService.CheckedEplan(eplanId);		
	}

	/**
	 * 查询一个计划
	 * @param eplan_Id
	 * @return
	 */
	@RequestMapping("/get_EplanOne")
	@ResponseBody
	public Map<String,Object> getEplanOne(String eplan_Id){
		long eplanId=Long.parseLong(eplan_Id);
		return equipPlanService.getEplanOne(eplanId);
	}
	/**
	 * 查询一个计划的详情
	 * @param eplan_id
	 * @return
	 */
	@RequestMapping("/get_EplanOneDetail")
	@ResponseBody
	public Map<String,Object> getEplanDetail(String eplan_id,int page, int rows){
		return equipPlanService.getEplanDetail(eplan_id, page, rows);
	}
	@RequestMapping("/get_EplanOneDetailAll")
	@ResponseBody
	public Map<String,Object> getEplanDetailAll(String eplan_id){
		return equipPlanService.getEplanDetail(eplan_id);
	}
	/**
	 * 查询全部计划分页第一页
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/get_equiplanAll")
	@ResponseBody
	public Map<String,Object> getEplan(int page, int rows){
		return equipPlanService.getEplan(page, rows);
		
	}
	/**
	 * 条件查询计划
	 * @param page
	 * @param rows
	 * @param eplanType
	 * @param eplan_date
	 * @param eplan_author
	 * @param eplan_title
	 * @return
	 */
	@RequestMapping("/get_equiplanWhere")
	@ResponseBody
	public Map<String,Object> getEplanWhere(int page, int rows,String eplanType,String eplanDate,String eplanAuthor,String eplanTitle){
		return equipPlanService.getEplanWhere(page, rows, eplanType, eplanDate, eplanAuthor, eplanTitle);
	}
	/**
	 * 查询已审核计划
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/get_CheckedEplan")
	@ResponseBody
	public  Map<String,Object> getCheckedEplan(int page, int rows){
		return equipPlanService.getCheckedEplan(page, rows);	
	}
	/**
	 * 条件查询已审核计划
	 * @param page
	 * @param rows
	 * @param eplanType
	 * @param eplanDate
	 * @param eplanDept
	 * @return
	 */
	@RequestMapping("/get_CheckedEplanWhere")
	@ResponseBody
	public  Map<String,Object> getCheckedEplanWhere(int page, int rows,String eplanType,String eplanDate,String eplanDept){
		return equipPlanService.getCheckedEplanWhere(page, rows,eplanType,eplanDate,eplanDept);	
	}
	/**
	 * 添加外包商
	 */
	@Autowired
	private BusinessService businessService;
	
	@PostMapping("/add_business")
	@ResponseBody
	public Info addBusiness(BusinessVo businessVo){
		boolean flag = businessService.addBusiness(businessVo.getBusiness(), 
				Arrays.asList(businessVo.getBusPeople()));
		return flag ? new Info() : new Info("外包商增加失败！");
	}
	/**
	 * 编辑
	 * @param busId
	 * @param businessVo
	 * @return
	 */
	@PostMapping("/edite_business")
	@ResponseBody
	public Info editeBusiness(long busId,BusinessVo businessVo){
		boolean flag = businessService.editeBusiness(busId,businessVo.getBusiness(), 
				Arrays.asList(businessVo.getBusPeople()));
		return flag ? new Info() : new Info("外包商编辑失败！");
	}
	/**
	 * 查询外包商分页第一页
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/get_BusinessAll")
	@ResponseBody
	public Map<String,Object> getBusiness(int page, int rows){
		return businessService.getBusiness(page, rows);
		
	}
	/**
	 * 查询供应商
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/get_SupplierBusiness")
	@ResponseBody
	public Map<String,Object> SupplierBusiness(int page, int rows){
		return businessService.getSupplierBusiness(page, rows);
	}
	
	/**
	 * 条件查询外包商分页第一页
	 * @param page
	 * @param rows
	 * @param busType
	 * @param busName
	 * @param busAddress
	 * @return
	 */
	@RequestMapping("/get_BusinessWhere")
	@ResponseBody
	public Map<String,Object> getBusinessWhere(int page,int rows,String busType,String busName,String busAddress){
		return businessService.getBusinessWhere(page, rows, busType, busName, busAddress);
	
	}
	/**
	 * 刪除外包商
	 * @param eplanId
	 */
	
	@PostMapping("/delete_business")
	@ResponseBody
	public boolean deleteBusiness(long busId){
		return businessService.deleteBusiness(busId);
		
	}
	/**
	 * 查询一个外商的联系人
	 * @param businessId
	 * @return
	 */
	@RequestMapping("/get_BusinessOnePeople")
	@ResponseBody
	public Map<String,Object> getBusinessOnePeople(long businessId){
		return businessService.BusinessOnePeople( businessId);
	}
	@Autowired
	private OrderPlanService orderPlanService;
	@Autowired
	private EplanOrderService eplanOrderPlanService;
	/**
	 * 生成订单号
	 * @return
	 */
	@RequestMapping("/to_EquipOrderId")
	@ResponseBody
	public String initEquipOrderId(){
		return orderPlanService.createOrderId();
	}
	/**
	 * 查询已订购订单
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/get_BuyEplanOrder")
	@ResponseBody
	public  Map<String,Object> getBuyEplanOrder(int page, int rows){
		return eplanOrderPlanService.getBuyEplanOrder(page, rows);	
	}
	/**
	 * 查询部分入库的订单
	 * @param page
	 * @param rows
	 * @return
	 *//*
	@RequestMapping("/get_SaveSomeEplanOrder")
	@ResponseBody
	public  Map<String,Object> SaveSomeEplanOrder(int page, int rows){
		return eplanOrderPlanService.SaveSomeEplanOrder(page, rows);	
	}*/
	/**
	 * 修改订单状态为已入库
	 * @param eplanOrder_Id
	 * @return
	 */
	@RequestMapping("/set_OrderSaveState")
	@ResponseBody
	public boolean SetOrderSaveState(String eplanOrder_Id){
		return eplanOrderPlanService.SetOrderSaveState(eplanOrder_Id);
		
	}
	@RequestMapping("/set_OrderDelete")
	@ResponseBody
	public boolean SetOrderDeleteState(String eplanOrder_Id){
		return eplanOrderPlanService.SetOrderDeleteState(eplanOrder_Id);
		
	}
	/**
	 * 添加订单
	 * @param eplanId
	 * @param equipOrder
	 * @return
	 */
	@PostMapping("/add_EquipOrder_sss")
	@ResponseBody
	public Info addEquipOrder(long eplanId,EquipOrder equipOrder){
		boolean flag = eplanOrderPlanService.addEplanOrder(eplanId,equipOrder);
		return flag  ? new Info() : new Info("添加订单失败！");
		
	}
	/**
	 * 获取所有订单list
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/get_EquipOrderAll_list")
	@ResponseBody
	public Map<String,Object> getEplanOrder(int page,int rows){
		return eplanOrderPlanService.getEplanOrder(page, rows);
		
	}
	/**
	 * 条件查询订单
	 * @param page
	 * @param rows
	 * @param equipOrderId
	 * @param businessName
	 * @param eorderName
	 * @param eorderState
	 * @return
	 */
	@RequestMapping("/get_EquipOrderWhere")
	@ResponseBody
	public Map<String,Object> getEplanOrderWhere(int page,int rows,String equipOrderId,String businessName,String eorderName,String eorderState){
		return eplanOrderPlanService.getEplanOrderWhere(page, rows,equipOrderId,businessName,eorderName,eorderState);
		
	}
	/**
	 * 条件查询已订购订单
	 * @param page
	 * @param rows
	 * @param equipOrderId
	 * @param businessName
	 * @param eorderName
	 * @return
	 */
	@RequestMapping("/get_BuyOrderWhere")
	@ResponseBody
	public Map<String,Object> getBuyOrderWhere(int page,int rows,String equipOrderId,String businessName,String eorderName){
		return eplanOrderPlanService.getBuyOrderWhere(page, rows,equipOrderId,businessName,eorderName);
		
	}
	
	@Autowired
	private EquipStorageService equipStorageService;
	/**
	 * 入库id号
	 * @return
	 */
	@RequestMapping("/to_equipStorageId")
	@ResponseBody
	public String initStorageId(){
		return equipStorageService.equipStorageId();
	}
	/**
	 * 入库操作
	 */
	
	/**
	 * @param businessName
	 * @param equipOrderId
	 * @param equipStorageVo
	 * @return
	 */
	@PostMapping("/save_equipOrderStroage")
	@ResponseBody
	public Info saveEquipOrderStroage(String businessName,String equipOrderId,EquipStorageVo equipStorageVo){

		boolean flag = equipStorageService.saveEquipOrderStroage(businessName,equipOrderId,equipStorageVo.getEquipStorage(), 
				Arrays.asList(equipStorageVo.getStorageDetails()));
		return flag ? new Info() : new Info("入库失败！");
	}
	/**
	 * 库存查询页面
	 * @return
	 */
	@GetMapping("/to_room_select")
	public String toRoomSelect(){
		return "equip_room_select";
		
	}
	/**
	 * 查询所有库存
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/get_equipStroageSaveAll")
	@ResponseBody
	public Map<String,Object> getequipStroageSave(int page, int rows){
		return equipStorageService.getequipStroageSave(page, rows);
		
	}
	/**
	 * 条件查询
	 * @param page
	 * @param rows
	 * @param equipsaveBatchId
	 * @param equipsaveBatchName
	 * @param equipsaveBatchEdate
	 * @return
	 */
	@RequestMapping("/get_equipStroageSaveWhere")
	@ResponseBody
	public Map<String,Object> getEquipStroageSaveWhere(int page,int rows,String equipsaveBatchId,String equipsaveBatchName,String equipsaveBatchEdate){
		return equipStorageService.getEquipStroageSaveWhere(page, rows, equipsaveBatchId, equipsaveBatchName, equipsaveBatchEdate);
	
	}
	/**
	 * 设置库存状态
	 * @param equipsaveid
	 */
	@RequestMapping("/set_EquipSaveState")
	@ResponseBody
	public boolean setEquipSaveState(long equipsaveid){
		return equipStorageService.setEquipSaveState(equipsaveid);
	}
	/**
	 * 设置库存状态可以用
	 * @param equipsaveid
	 */
	@RequestMapping("/set_EquipSaveStateOk")
	@ResponseBody
	public boolean setEquipSaveStateOk(long equipsaveid){
		return equipStorageService.setEquipSaveStateOk(equipsaveid);
	}
	/**
	 * 删除该库存
	 * @param equipsaveid
	 * @return
	 */
	@RequestMapping("/set_EquipSaveMove")
	@ResponseBody
	public boolean setEquipSaveMove(long equipsaveid){
		return equipStorageService.EquipSaveMove(equipsaveid);
	}
	/**
	 * 库存退货
	 */
	@Autowired
	private StorageReturnService returnService;
	/**
	 * 生成退货订单号
	 * @return
	 */
	@RequestMapping("/to_EquipReturnId")
	@ResponseBody
	public String initEquipReturnId(){
		return returnService.createEquipReturnId();
	}
	/**
	 * 查询被禁用的设备
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/get_unableESOlist")
	@ResponseBody
	public Map<String,Object> getUnableESOlist(int page,int rows){
		return equipStorageService.getUnableESOlist(page, rows);
	
	}
	/**
	 * 条件查询退货设备
	 * @param page
	 * @param rows
	 * @param businessName
	 * @return
	 */
	@RequestMapping("/get_unableESOlistWhere")
	@ResponseBody
	public Map<String,Object> getUnableESOlistWhere(int page,int rows,String businessName){
		return equipStorageService.getUnableESOlistWhere(page, rows,businessName);
	
	}
	@RequestMapping("/get_ableESOlistWhere")
	@ResponseBody
	public Map<String,Object> getAbleESOlistWhere(int page,int rows,String equipName){
		return equipStorageService.getAbleESOlistWhere(page, rows,equipName);
	
	}
	/**
	 * 查询可以使用的库存
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/get_ableESOlist")
	@ResponseBody
	public Map<String,Object> getAbleESOlist(int page,int rows){
		return equipStorageService.getAbleESOlist(page, rows);
	
	}
	/**
	 * 退货订单保存
	 * @param eosReturnVo
	 * @return
	 */
	@PostMapping("/get_EosReturn")
	@ResponseBody
	public Info EosReturn(EosReturnVo eosReturnVo){
		boolean flag =returnService.EosReturn(eosReturnVo.getReturnGood(), 
				Arrays.asList(eosReturnVo.getReturnDetail()),eosReturnVo.getRdetailEquipsaveid())	;			
		return flag ? new Info() : new Info("退货失败！");
	}
	/**
	 * 领用
	 */
	@Autowired
	private EquipDeliveryService deliveryService;
	
	@RequestMapping("/to_delivery_list")
	public String toDeliveryList(){
		return "equip_save_delivery";
		
	}
	/**
	 * 产生领用ID
	 * @return
	 */
	@RequestMapping("/to_DeliveryId")
	@ResponseBody
	public String Delivery(){
		return deliveryService.creatDeliveryId();
	}
	/**
	 * 保存领用单
	 * @param eosDeliveryVo
	 * @return
	 */
	@PostMapping("/get_DeliverySave")
	@ResponseBody
	public Info EosDelivery(EosDeliveryVo eosDeliveryVo){
		boolean flag =deliveryService.deliverySave(eosDeliveryVo.getDelivery(), 
				Arrays.asList(eosDeliveryVo.getDeliveryDetail()))	;			
		return flag ? new Info() : new Info("领用失败！");
	}
	/**
	 * 添加维修申请
	 */
	@Autowired
	private EquipRepairService equipRepairService;
	
	@PostMapping("/add_repair")
	@ResponseBody
	public Info addEquipRepair(EquipRepair repair){
		boolean flag = equipRepairService.addEquipRepair(repair);
		return flag ? new Info() : new Info("添加维修申请失败！");
	}
	/**
	 * 外加接诊页面
	 */
	@GetMapping("/to_receive_patient_treatment")
	public String toReceivePatientTreatment(){
		return "receive_patient_treatment";
		
	}
	@Autowired
	private PatientRegistrationService registrationService;
	
	@RequestMapping("/get_OneDoctorRegistration")
	@ResponseBody
	public Map<String,Object> findOneDoctorRegistration(int page,int rows,String doctorID){
		return registrationService.findOneDoctorRegistration(page, rows, doctorID);

	}
	
	@PostMapping("/update_Registration")
	@ResponseBody
	public boolean nextRegistration(String patient_reg_id){
		return registrationService.updateRegistration(patient_reg_id);		
	}
	
}
